package com.kgc.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SendPhoneMessage {
    public String sendMessage(String phone){
        String accessKeyId = "LTAIGqVUmIdN3RwQ";
        String accessSecret = "Wn8p4GU7XhzORjUtaIvu5YS2IPVQtL";
        DefaultProfile profile = DefaultProfile.getProfile("default", accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);

        String number=(int)((Math.random()*900000+1))+"";
        String codenum="{\"code\":\""+number+"\"}";


        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "大麦短信轰炸区");
        request.putQueryParameter("TemplateCode", "SMS_172505037");
        request.putQueryParameter("TemplateParam", codenum);
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
            return number;
    }
}